package com.dyz.LeetCodeforSwordFingerOffer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: daiyizheng
 * @date: 2021/7/3 12:23
 * @description:
 */
public class kthLargest54 {
    public int kthLargest(TreeNode root, int k) {
        //二叉收索树的中序遍历是从小到大排序
        if(root==null||k<1){return Integer.MIN_VALUE;}
        //中序遍历
        List<Integer> list = new ArrayList<>();
        addList(list, root);
        int size = list.size();
        if(size<k){return  Integer.MIN_VALUE;}
        return list.get(size-k);

    }
    private static void addList(List list, TreeNode node){
        if(node==null){return;}
        if(node.left!=null){addList(list, node.left);}
        list.add(node.val);
        if (node.right!=null){addList(list, node.right);}
    }
}
